package com.gxa.meiye.admin.shop.controller;

import com.gxa.meiye.admin.shop.service.OrderManagementService;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.common.ResponseData;
import com.gxa.meiye.core.pojo.shopManagement.OrderManagement;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author cc
 * @PackageName meiye
 * @Package com.gxa.meiye.admin.shop.controller
 * @Date 2022/7/23 23:16
 * @Version 1.0
 */
@RestController
@RequestMapping("shopOrder")
@Api(tags = "订单管理接口")
@Slf4j
public class AdminOderManagementController {
    @Autowired
    private OrderManagementService orderManagementService;
    @ApiOperation("点击订单管理查询所有")
    @GetMapping("allOrder")
    public ResponseData getAllOder(){
       ResponseData rd = new ResponseData();
        List<OrderManagement> all = orderManagementService.getAll();
        Integer allCount = orderManagementService.getAllCount();
        rd.setCount(allCount);
        rd.setCode(200);
        rd.setMsg("查询成功");
        rd.setData(all);
        return rd;
    }

    @ApiOperation("根据条件模糊查询 1待支付 2待服务 4已完成 7退款中 8已退款 6已取消")
    @GetMapping("selectByCondition")
    public Map queryByCondition(@RequestParam Integer pageNum,
                                @RequestParam  Integer pageSize, OrderManagement orderManagement){
        JsonResult jsonResult = new JsonResult();
        pageNum = (pageNum-1)*pageSize;
        Integer total = orderManagementService.conditionAll(orderManagement);
        String endTime = orderManagement.getEndTime();
        String orderNumber = orderManagement.getOrderNumber();
        String phone = orderManagement.getPhone();
        String startTime = orderManagement.getStartTime();
        Integer status = orderManagement.getStatus();
        List<OrderManagement> data = orderManagementService.getByCondition(pageNum, pageSize, endTime,orderNumber, phone,startTime,status);
        jsonResult.set("data",data);
        jsonResult.set("total",total);
        return jsonResult.getMap();
    }

    @ApiOperation("在操作栏都加上核销 状态为已完成才能核销并删除数据")
    @DeleteMapping("deleteOrder")
    public ResponseData removeOrder(Integer status){
        ResponseData rd = new ResponseData();

        Integer deleteOrder = orderManagementService.deleteOrder(status);
        if(deleteOrder!=0){
            rd.setCode(200);
            rd.setMsg("删除成功");
        }else {
            rd.setMsg("当前订单还未完成，不能删除订单");
        }
        return rd;

    }

}
